#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
long long a[N], b[N];
signed main() {
  int q;
  cin >> q;
  long long l = 1, r = 0, sum = 0, del = 0;
  while (q--) {
    int op;
    cin >> op;
    if (op == 1) {
      int x;
      cin >> x;
      a[++r] = sum;
      b[r] = x;
      sum += x;
    } else if (op == 2) {
      del += b[l++];
    } else {
      int x;
      cin >> x;
      // cout << l << ' ' << r << ' ' << del << endl;
      cout << a[l + x - 1] - del << endl;
    }
  }
  return 0;
}